package test;

public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() ->{
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hahah");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //1.不操作继续执行线程（因为sleep唤醒后会又将标志位改为true）
                   e.printStackTrace();

                    //2.结束线程
                    break;
                    //3.进行其它操作
                }
            }
        });
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }
}


